{
 "cells": [
  {
   "cell_type": "code",
   "execution_count": 1,
   "metadata": {},
   "outputs": [
    {
     "name": "stderr",
     "output_type": "stream",
     "text": [
      "C:\\ProgramData\\Anaconda3\\lib\\site-packages\\h5py\\__init__.py:36: FutureWarning: Conversion of the second argument of issubdtype from `float` to `np.floating` is deprecated. In future, it will be treated as `np.float64 == np.dtype(float).type`.\n",
      "  from ._conv import register_converters as _register_converters\n"
     ]
    }
   ],
   "source": [
    "import tensorflow as tf\n",
    "import numpy as np\n",
    "import matplotlib.pyplot as plt\n",
    "%matplotlib inline"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 2,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = tf.placeholder(tf.float32)\n",
    "y = tf.placeholder(tf.float32)\n",
    "c = tf.constant(5)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 3,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<tf.Tensor 'Placeholder:0' shape=<unknown> dtype=float32>"
      ]
     },
     "execution_count": 3,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "x"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 4,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<tf.Tensor 'mul:0' shape=() dtype=int32>"
      ]
     },
     "execution_count": 4,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "c*2"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 5,
   "metadata": {},
   "outputs": [],
   "source": [
    "square_node = x*x\n",
    "mult_node = square_node*y\n",
    "quadruple_node = 4*y\n",
    "adder_node = mult_node + quadruple_node"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 6,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<tf.Tensor 'mul_1:0' shape=<unknown> dtype=float32>"
      ]
     },
     "execution_count": 6,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "square_node"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 7,
   "metadata": {},
   "outputs": [],
   "source": [
    "sess = tf.Session()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 8,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "5"
      ]
     },
     "execution_count": 8,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sess.run(c)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 9,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array(10., dtype=float32)"
      ]
     },
     "execution_count": 9,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sess.run(x, feed_dict={x:10})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 10,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "25.0"
      ]
     },
     "execution_count": 10,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sess.run(square_node, feed_dict={x:5})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 11,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "26.0"
      ]
     },
     "execution_count": 11,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sess.run(adder_node, feed_dict={x:3, y:2})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 12,
   "metadata": {},
   "outputs": [],
   "source": [
    "f = x**2 * y + 4*y"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 13,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "<tf.Tensor 'add_1:0' shape=<unknown> dtype=float32>"
      ]
     },
     "execution_count": 13,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "f"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 14,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "26.0"
      ]
     },
     "execution_count": 14,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "sess.run(f, feed_dict={x:3, y:2})"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 15,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "f(10,5)= 520.0\n",
      "f(10,5)= 520.0\n"
     ]
    }
   ],
   "source": [
    "with tf.Session() as sess:\n",
    "    print(\"f(10,5)=\", sess.run(f, feed_dict={x:10, y:5}))\n",
    "    print(\"f(10,5)=\", f.eval(feed_dict={x:10, y:5}))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 16,
   "metadata": {},
   "outputs": [],
   "source": [
    "np.random.seed(123)\n",
    "x_train = np.arange(0,10,0.25)\n",
    "y_train = 5*x_train + 1 + np.random.normal(0,1,size=x_train.shape)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 17,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "image/png": "iVBORw0KGgoAAAANSUhEUgAAAXQAAAD8CAYAAABn919SAAAABHNCSVQICAgIfAhkiAAAAAlwSFlzAAALEgAACxIB0t1+/AAAADl0RVh0U29mdHdhcmUAbWF0cGxvdGxpYiB2ZXJzaW9uIDIuMi4yLCBodHRwOi8vbWF0cGxvdGxpYi5vcmcvhp/UCwAAElhJREFUeJzt3W+MXNV9xvHnqe2IDWm0EAwya1y7kuWCaiWORojWUpSaUJM/ii0rqUjbyKqQ/Ia2pEROTN+0fVHZFVWSvqiorEBjqZQQEbAt0oYgGxSlqihrTAPERaaUEK9d7DTZhlRWg8mvL/ZubeyduXfn/pm5534/EtqZOzN7z4B5OPzu75zriBAAoP1+YdQDAABUg0AHgEQQ6ACQCAIdABJBoANAIgh0AEgEgQ4AiSDQASARBDoAJGJpkye76qqrYvXq1U2eEgBa78iRIz+MiOV572s00FevXq3p6ekmTwkArWf7+0XeR8kFABJBoANAIgh0AEgEgQ4AiSDQASARhbpcbL8q6Q1Jb0k6FxE921dKekjSakmvSvqtiPhxPcMEgPbZf3RG9zz+kk7OntW1kxPauXmdtm6Yqu18i5mh/0ZEvC8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2Ms2F+QMR8ciox9OQjZI+bvtVzZXXNtn+u9EOqTEnJJ2IiPn/E3tYcwGfug9J+o+IOBMRb0p6RNKvj3hMTXvd9gpJyn6eHuaXtCHQa78Z9Tiybc3VUo9FxBdGPZ6mRMTdEbEyIlZr7p/14YjoxGwtIv5T0g9sz98F/WZJ3xvhkJrymqSbbL8z+3N/szpwMfgiByVtzx5vl3RgmF8y9E2im9LEzajH1EZJn5b0vO3nsmN/HBH/MMIxoX5/IOmBbPLyiqTfG/F4ahcRT9t+WNKzmuvuOqqEV4zaflDSByVdZfuEpD+RtEfS12zfrrn/wH1yqN/NSlEASEMbSi4AgAIIdABIBIEOAIkg0AEgEQQ6ACSCQAeARBDoAJAIAh0AEvF/M2WkT2eh6ykAAAAASUVORK5CYII=\n",
      "text/plain": [
       "<Figure size 432x288 with 1 Axes>"
      ]
     },
     "metadata": {},
     "output_type": "display_data"
    }
   ],
   "source": [
    "plt.scatter(x_train, y_train);"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 18,
   "metadata": {},
   "outputs": [],
   "source": [
    "w = tf.Variable(0.0, dtype=tf.float32)\n",
    "b = tf.Variable(0.0, dtype=tf.float32)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 19,
   "metadata": {},
   "outputs": [],
   "source": [
    "x = tf.placeholder(tf.float32)\n",
    "y = tf.placeholder(tf.float32)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 20,
   "metadata": {},
   "outputs": [],
   "source": [
    "linear_model = w * x + b "
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 21,
   "metadata": {},
   "outputs": [],
   "source": [
    "loss = tf.reduce_sum(tf.square(linear_model - y))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 22,
   "metadata": {},
   "outputs": [],
   "source": [
    "optimizer = tf.train.GradientDescentOptimizer(learning_rate=0.0005)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 23,
   "metadata": {},
   "outputs": [],
   "source": [
    "training_op = optimizer.minimize(loss)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 24,
   "metadata": {},
   "outputs": [],
   "source": [
    "init = tf.global_variables_initializer()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 25,
   "metadata": {},
   "outputs": [],
   "source": [
    "sess = tf.Session()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 26,
   "metadata": {},
   "outputs": [],
   "source": [
    "sess.run(init)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 27,
   "metadata": {},
   "outputs": [
    {
     "name": "stdout",
     "output_type": "stream",
     "text": [
      "Iteration 0: w: 6.58667, b: 1.01166\n",
      "Iteration 1: w: 4.52043, b: 0.69846\n",
      "Iteration 2: w: 5.16780, b: 0.80070\n",
      "Iteration 3: w: 4.96417, b: 0.77262\n",
      "Iteration 4: w: 5.02743, b: 0.78537\n",
      "Iteration 5: w: 5.00699, b: 0.78527\n",
      "Iteration 6: w: 5.01281, b: 0.78916\n",
      "Iteration 7: w: 5.01040, b: 0.79176\n",
      "Iteration 8: w: 5.01058, b: 0.79473\n",
      "Iteration 9: w: 5.00995, b: 0.79754\n",
      "Iteration 10: w: 5.00958, b: 0.80036\n",
      "Iteration 11: w: 5.00913, b: 0.80315\n",
      "Iteration 12: w: 5.00872, b: 0.80590\n",
      "Iteration 13: w: 5.00830, b: 0.80863\n",
      "Iteration 14: w: 5.00788, b: 0.81134\n",
      "Iteration 15: w: 5.00747, b: 0.81401\n",
      "Iteration 16: w: 5.00707, b: 0.81666\n",
      "Iteration 17: w: 5.00667, b: 0.81928\n",
      "Iteration 18: w: 5.00627, b: 0.82187\n",
      "Iteration 19: w: 5.00588, b: 0.82444\n"
     ]
    }
   ],
   "source": [
    "for i in range(20):\n",
    "    sess.run(training_op, feed_dict={x: x_train, y: y_train})\n",
    "    print(\"Iteration {}: w: {:0.5f}, b: {:0.5f}\".format(i, sess.run(w), sess.run(b)))"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 28,
   "metadata": {},
   "outputs": [],
   "source": [
    "X = np.vstack((x_train, np.ones_like(x_train))).transpose()"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": 29,
   "metadata": {},
   "outputs": [
    {
     "data": {
      "text/plain": [
       "array([4.9675195, 1.0749621])"
      ]
     },
     "execution_count": 29,
     "metadata": {},
     "output_type": "execute_result"
    }
   ],
   "source": [
    "L = np.linalg.inv(X.transpose().dot(X))\n",
    "R = X.transpose().dot(y_train)\n",
    "L.dot(R)"
   ]
  },
  {
   "cell_type": "code",
   "execution_count": null,
   "metadata": {},
   "outputs": [],
   "source": []
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "codemirror_mode": {
    "name": "ipython",
    "version": 3
   },
   "file_extension": ".py",
   "mimetype": "text/x-python",
   "name": "python",
   "nbconvert_exporter": "python",
   "pygments_lexer": "ipython3",
   "version": "3.6.5"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 2
}
